﻿using System;
using System.IO;
using Com.Pernix.Common.Linq;
namespace Com.Pernix.Common.File
{
    public static class FileUtil
    {
        public static bool CreateDirIfNotExist(string targetPath)
        {
            var dir = new DirectoryInfo(targetPath);
            if (!dir.Exists)
            {
                dir.Create();
                return true;
            }
            return false;
        }

        public static String[] GetFileNameInDir(String directoryPath)
        {
            string[] filePaths = Directory.GetFiles(directoryPath);
            return filePaths;
        }

        public static string GetDirectory(string path)
        {
            string extension = Path.GetExtension(path);
            if (!extension.IsNullOrEmpty())
            {
                string filename = Path.GetFileName(path);
                if (!filename.IsNullOrEmpty())
                {
                    return path.Replace(filename, "");
                }
            }
            return path;
        }
    }
}
